const route = require('koa-router')();
const bill = require('../../model/bill/bill.js')
const transArr = require('../../utils/transArray.js')
const format = require('../../utils/formatTime.js')

route.post('/get_bill',async(ctx,next)=>{
    let reqData = ctx.request.body
    // let info = await bill.find({
    //     user_id:reqData.user_id,
    //     addDate:{
    //         '$gte':new Date(`${reqData.year}-${reqData.month}-1`),
    //         '$lte':new Date(`${reqData.year}-${Number(reqData.month)+1}-1`),
    //     }
    // }).sort({'addDate':1}).populate("adminClassify","class_id id").exec()
    let info = await bill.aggregate([
        {
            $match:{
                user_id:Number(reqData.user_id),
                addDate:{
                    '$gte':new Date(`${reqData.year}-${reqData.month}-1`),
                    '$lte':new Date(`${reqData.year}-${Number(reqData.month)+1}-1`),
                }
            }
        },
        {
            $lookup:{
                from: 'adminClassify',  // 表示被关联的表
                localField: 'class_id',  // 关联条件
                foreignField: 'id',
                as: 'class_info',  // 将查询到的数据放入order_info
            }
        }
    ])
    ctx.body = {
        code:200,
        data:transArr(info)
    }
})

module.exports = route